import request from '@/utils/request'
// 通用表操作方法
export function Get(id, args) {
  return request({
    url: `/crm/api/crmm/${id || ''}${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

export function Post(data) {
  // 如果没有table_name参数 报错
  if (!data.table_name) {
    return new Promise((resolve, reject) => {
      reject('table_name is required')
    })
  }
  return request({
    url: '/crm/api/crmm/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

export function Put(id, data) {
  // 如果没有table_name参数 报错
  if (!data.table_name) {
    return new Promise((resolve, reject) => {
      reject('table_name is required')
    })
  }
  return request({
    url: `/crm/api/crmm/${id || ''}`,
    headers: { 'content-type': 'application/json' },
    method: 'put',
    data: JSON.stringify(data)
  })
}

export function Delete(id, data) {
  // 如果没有table_name参数 报错
  if (!data.table_name) {
    return new Promise((resolve, reject) => {
      reject('table_name is required')
    })
  }
  return request({
    url: `/crm/api/crmm/${id || ''}`,
    method: 'delete',
    data: JSON.stringify(data)
  })
}

export function GetCustomerCategories() {
  return request({
    url: `/crm/api/crmm/?table_name=CRMCustomerCategory`,
    method: 'get'
  })
}
